CONFLICT=${wildcard *.conflict}
CONSISTENT=${wildcard *.consistent}
INCONCLUSIVE=${wildcard *.inconclusive}

EXECUTABLE=${wildcard ../bin/gmini*}

TESTS=$(CONFLICT:.conflict=.NO) $(CONSISTENT:.consistent=.YES) $(INCONCLUSIVE:.inconclusive=.UNKNOWN)

CHECK =$(CONFLICT:.conflict=.N) $(CONSISTENT:.consistent=.Y) $(INCONCLUSIVE:.inconclusive=.U)

test: executable $(TESTS) $(CHECK) clean

executable:
ifeq ($(EXECUTABLE),)
	@cd ../bin/; $(MAKE); cd -;
endif

%.YES: %.consistent
	@$(EXECUTABLE) ../examples/$*.mini $< > $@
	
%.NO: %.conflict
	@$(EXECUTABLE) ../examples/$*.mini $< > $@

%.UNKNOWN: %.inconclusive
	@$(EXECUTABLE) ../examples/$*.mini $< > $@

%.Y: %.YES
	@if [ $< != `grep -l -n 'Consistent!' $<` ]; \
	then  \
		echo $*.mini with $*.consistent = FAIL; \
	else \
		echo $*.mini with $*.consistent = PASS; \
	fi
	
%.N: %.NO
	@if [ $< != `grep -l -n 'Conflict!' $<` ] ;\
	then 	\
		echo $*.mini with $*.conflict = FAIL; \
	else \
		echo $*.mini with $*.conflict = PASS; \
	fi;

%.U: %.UNKNOWN
	@if [ $< != `grep -l -n 'Inconclusive!' $<` ];\
	then  \
		echo $*.mini with $*.inconclusive = FAIL; \
	else \
		echo $*.mini with $*.inconclusive = PASS; \
	fi;

clean:
	@rm -f *.NO *.YES *.UNKNOWN
